package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.ArraylistStudentDao;
import com.itheima.info.manager.dao.BaseStudentDao;
import com.itheima.info.manager.dao.StudentDao;
import com.itheima.info.manager.domain.Student;
import com.itheima.info.manager.factory.StudentDaoFactory;

public class StudentService {
    //ArraylistStudentDao arraylistStudentDao=new ArraylistStudentDao();

    private BaseStudentDao studentDao=StudentDaoFactory.getStudentDao();

    public boolean addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    public Student[] findAllStudent() {
        Student[] students = studentDao.findAllStudent();

        boolean flag = false;
        for (int i = 0; i < students.length; i++) {
            if (null != students[i]) {
                flag = true;
                break;
            }
        }
        if (flag) return students;
        else return null;

    }

    public boolean isExists(String id) {
        Student[] students=studentDao.findAllStudent();

        boolean exists=false;
        for (int i = 0; i < students.length; i++) {
            if (null!=students[i]&&students[i].getId().equals(id)) {
                exists=true;
                break;
            }
        }
        return exists;
    }

    public void deleteStudentById(String deleteId) {
        studentDao.deleteStudentById(deleteId);
    }

    public void updateStudent(String updateId, Student newStudent) {
        studentDao.updateStudent(updateId,newStudent);
    }
}
